﻿@model Content
@{ 
    var comments = ViewData["Comments"] as IEnumerable<ContentComment>;//回复
    var notAnwserList = ViewData["NotAnwserList"] as IEnumerable<Content>;//等待回复的问答
    var userContents = ViewData["UserContents"] as IEnumerable<Content>;//
    var bestAnswer = ViewData["BestAnswer"] as  ContentComment;//最佳答案
}
<div class="container mt-3 mb-3">
    <div class="row">
        <div class="col-md-8 col-sm-12">
            
            <div class="row">
                <div class="col">
                    <div class="border-bottom mb-3 row">
                        <div class="col-md-9 col-sm-12">
                            <h3>
                                <span class="badge badge-warning">问</span>
                                @if (Model.IsLockComment)
                                {
                                    <span class="badge badge-secondary"><i class="fa fa-lock"></i></span>
                                }
                                @Model.Subject
                            </h3>
                            <ul class="list-inline text-muted mt-3 text-sm">
                                <li class="list-inline-item">@Model.Category?.Name</li>
                                <li class="list-inline-item"><i class="far fa-calendar-alt"></i> @Model.PostedTime.ToChineseDateTimeString()</li>
                                <li class="list-inline-item"><i class="fas fa-eye"></i> @Model.VisitNum</li>
                                <li class="list-inline-item"><i class="far fa-comments"></i> @comments.Count()</li>
                            </ul>
                        </div>
                        <div class="col-md-3 d-none d-md-block">
                            <div class="border rounded text-center p-1">
                                <h3>悬赏</h3>
                                <h4>
                                    <i class="fa fa-database text-golden"></i>
                                    <span class="text-xxl"><b>@Model.Cost</b> 个金币</span>
                                </h4>
                            </div>
                        </div>

                        <div class="col-12">

                            <div class="bdsharebuttonbox">
                                <a href="#" class="bds_more" data-cmd="more"></a>
                                <a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a>
                                <a href="#" class="bds_sqq" data-cmd="sqq" title="分享到QQ好友"></a>
                                <a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a>
                                <a href="#" class="bds_youdao" data-cmd="youdao" title="分享到有道云笔记"></a>
                                <a href="#" class="bds_copy" data-cmd="copy" title="分享到复制网址"></a>
                            </div>
                            <script>
                                    window._bd_share_config = {
                                        "common": {
                                            "bdSnsKey": {},
                                            "bdText": "@Html.Raw(Model.Subject)",
                                            "bdMini": "1",
                                            "bdMiniList": false,
                                            "bdPic": "",
                                            "bdDesc": '@Html.Raw(Model.Subject)',
                                            "bdStyle": "0",
                                            "bdSize": "32"
                                        },
                                        "share": {},
                                        "image": {
                                            "viewList": ["weixin", "qzone", "sqq", "tsina", "youdao", "copy"],
                                            "viewText": "分享到：", "viewSize": "16"
                                        }
                                    };
                                    with (document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];
                            </script>
                        </div>
                    </div>


                    @Html.Partial("/Pages/Shared/_MarkdownBody.cshtml", new MarkdownBodyViewModel { Id = $"content-{Model.Id}", Body = Model.Body, MinHeight = 300 })

                    @if (bestAnswer != null)
                    {
                        <div class="alert alert-success">
                            <div class="row">
                                <div class="col-12">
                                    <h4>最佳答案</h4>
                                    <hr />
                                    <div class="col-12 mt-3 mb-3">
                                        <ul class="list-inline">
                                            <li class="list-inline-item"><img src="@bestAnswer.Author.AvatarUrl"  class="img-avatar-25"/> @bestAnswer.Author.UserName </li>
                                            <li class="list-inline-item"><i class="fa fa-clock"></i> @bestAnswer.PostedTime.ToHumanDateTimeString()</li>
                                        </ul>
                                    </div>
                                    @Html.Partial("/Pages/Shared/_MarkdownBody.cshtml", new MarkdownBodyViewModel { Id = $"comment-{bestAnswer.Id}", Body = bestAnswer.Body })
                                </div>
                            </div>
                        </div>

                    }
                </div>
            </div>

            <!--标签-->
            <div class="border-top mt-3">
                <div class="float-left">
                    <i class="fa fa-tags"></i>
                    @foreach (var item in Model.GetTagNames())
                    {
                        <a asp-page="/Content/Search" asp-route-keyword="@item" target="_blank">
                            <span class="badge badge-info">@item</span>
                        </a>
                    }
                </div>
                <div class="float-right text-sm">
                    @if (User.Identity.IsAuthenticated && User.Identity.UserId() == Model.Author.Id && !Model.IsLockComment)
                    {
                        <a target="_blank" asp-page="./Edit" asp-route-id="@Model.Id" class=" text-muted"><i class="fa fa-edit"></i> 编辑</a>

                        <a href="javascript:removeContent('@Model.Id');" class=" text-muted"><i class="fa fa-trash"></i> 删除</a>
                    }
                </div>
            </div>

            <!--回复-->
            <div class="row mt-5">
                <div class="col-12">

                    <h4>相关回复(@comments.Count())</h4>
                    <hr>
                    @if (!comments.Any())
                    {
                        <div class="text-center mt-3">暂无任何数据</div>
                    }
                    else
                    {
                        <ul class="list-unstyled">

                            @foreach (var item in comments)
                            {
                                <li class="media mt-3 border-bottom p-2 rounded" id="comment-@item.Id">
                                    <a asp-page="/user/index" asp-route-userId="@item.Author.Id">
                                        <img class="mr-3 rounded img-avatar-100" src="@item.Author.AvatarUrl" alt="@item.Author.UserName">
                                        <p class="text-center">@item.Author.UserName</p>
                                    </a>
                                    <div class="media-body">
                                        @Html.Partial("/Pages/Shared/_MarkdownBody.cshtml", new MarkdownBodyViewModel { Id = $"comment-{item.Id}", Body = item.Body })
                                        <hr />

                                        <div class="row">
                                            <div class="col">
                                                <ul class="list-inline text-muted text-sm w-25">
                                                    <li class="list-inline-item"><i class="far fa-clock"></i> @item.PostedTime.ToHumanDateTimeString()</li>
                                                    @if (Model.BestCommentId.HasValue && Model.BestCommentId.Value == item.Id)
                                                    {
                                                    <li class="list-inline-item"><span class="badge badge-success">最佳答案</span></li>
                                                    }
                                                </ul>
                                            </div>
                                            @if (User.Identity.IsAuthenticated && User.Identity.UserId() == Model.AuthorId && item.AuthorId!=User.Identity.UserId()  && !Model.IsLockComment)
                                            {
                                                <div class="col-3">
                                                    <button class="btn btn-success btn-block" onclick="setBestAnswer('@item.Id',@Model.Id)"><i class="fa fa-thumbs-up"></i> 设为最佳答案</button>
                                                </div>
                                            }
                                        </div>
                                    </div>
                                </li>
                            }
                        </ul>
                    }
                </div>
                <div class="col-12 mt-3">
                    @if (Model.IsLockComment)
                    {
                        <div class="row">
                            <div class="text-center">
                                <div class="alert alert-default">
                                    <h3><i class="fa fa-lock"></i> 该帖子不允许回复！！</h3>
                                </div>
                            </div>
                        </div>
                    }
                    else
                    {
                        if (Model.InvitedUsers.Any())
                        {
                            <div>
                                <h4>邀请回复的用户</h4>
                                <hr />
                                <ul class="list-inline">
                                    @foreach (var item in Model.InvitedUsers)
                                    {
                                        <li class="list-inline-item mr-3">
                                            <a asp-page="/User/Index" asp-route-userid="@item.Id" target="_blank" class="text-primary">
                                                <img src="@item.AvatarUrl" class="img-avatar-25" /> @item.UserName
                                            </a>
                                        </li>
                                    }
                                </ul>
                            </div>
                        }

                        if (User.Identity.IsAuthenticated)
                        {
                            if (Model.OnlyInviteUser && !Model.InvitedUsers.Any(m => m.Id == User.Identity.UserId()))
                            {
                                <div class="text-center alert alert-warning">
                                    <h4>该帖子仅允许邀请的用户可进行回复！</h4>
                                </div>

                            }
                            else
                            {
                            <div class="row" id="comment">
                                <div class="col-12">
                                    <div class="input-group ">
                                        <textarea class="form-control " v-bind:style="{height:height}" @@focus="focus()" @@blur="blur()"
                                                  v-model="comment" placeholder="回复，大于5个字。支持 Markdown 语法" @@keydown.ctrl.enter="submit()">
</textarea>
                                        <div class="input-group-append">
                                            <button class="btn btn-primary btn-block btn-lg" v-on:click="submit()" v-bind:disabled="comment.length<5">
                                                提 交
                                                <br />
                                                Ctrl + Enter
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                                        }
                                    }
                                    else
                                    {
                            <div class="alert alert-warning">
                                <i class="fa fa-info-circle"></i> 登录后可回复，<a asp-page="/Account/Login" class="btn btn-dark" asp-route-returnUrl="@ViewContext.HttpContext.Request.ToRelativeUrl()"><i class="fas fa-sign-in-alt"></i> 点这里去登录</a>
                            </div>
                        }
                    }
                </div>
            </div>

        </div>
        <div class="col-md-4 d-none d-md-block">

            @(await Component.InvokeAsync("UserPanel", new { userId = Model.AuthorId }))

            <div class="mt-3 mb-3 border bg-light">
                <div class="border-bottom m-3"><b>TA 的提问</b></div>
                <div class="col">
                    @Html.Partial("_ListUnstyledAsk",userContents)
                </div>
            </div>

            <div class="mt-3 mb-3 border bg-light">
                <div class="border-bottom m-3"><b>等待解答</b></div>
                <div class="col">
                    @Html.Partial("_ListUnstyledAsk", notAnwserList)
                </div>
            </div>
        </div>
    </div>
</div>
@Html.Hidden("ArticleContent", Html.Raw(Model.Body))